package
{
	import flash.display.Sprite;
	
	import fl.controls.Label;
	
	public class MapPoint extends Sprite
	{
		
		public var mapId:int;
		
		public var targetPathMap:HashMap = new HashMap();
		
		private var _prePoint:MapPoint;

		public function get prePoint():MapPoint
		{
			return _prePoint;
		}

		public function set prePoint(value:MapPoint):void
		{
			_prePoint = value;
		}

		
		public function MapPoint(id:int,color:uint)
		{
			super();
			mapId = id;
			drawSkin(color);
			var label:Label = new Label();
			label.text = id+"";
			label.y = -50;
			this.addChild(label);
		}
		
		private function drawSkin(color:uint):void
		{
			graphics.beginFill(color,1);
			graphics.drawCircle(0,0,20);
			graphics.endFill();
		}
		
		public function setTargetPath(targetMapId:int,targetMapLine:MapLine):void
		{
			targetPathMap.put(targetMapId,targetMapLine);
		}
		
		public function getTargetPathById(targetMapId:int):MapLine
		{
			return targetPathMap.get(targetMapId) as MapLine;
		}
		
		public function findMiniDistanceMapLine(UndefindPointMap:HashMap):MapLine
		{
			var miniPath:MapLine;
			for each(var path:MapLine in targetPathMap.dict)
			{
				var targetPoint:MapPoint = UndefindPointMap.get(UintToByte.getEndId(path.mapLineId)) as MapPoint;
				
				if(targetPoint == null)
				{
					continue;
				}
				
				if(miniPath == null || miniPath.distance > path.distance)
				{
					miniPath = path;
				}
			}
			
			return miniPath;
		}
	}
}